package com.cerosoft.components;

import java.util.List;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ImageView;

import com.cerosoft.utils.IndexChangeListener;

public abstract class AbstractDynamicImageView extends ImageView implements
		IndexChangeListener {

	private List<String> imgs = null;

	private int currIndex = -1;

	private String ipAddr = null;

	public int getCurrIndex() {
		return currIndex;
	}

	public String getIpAddr() {
		return ipAddr;
	}

	public List<String> getImgs() {
		return imgs;
	}

	protected abstract void getViewByIndex();

	public void initView(List<String> imgs, String ipAddr, int currIndex) {
		this.imgs = imgs;
		this.ipAddr = ipAddr;
		this.currIndex = currIndex;
		getViewByIndex();
	}

	public AbstractDynamicImageView(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	@Override
	public int indexAdd() {
		if (imgs != null && currIndex < imgs.size() - 1) {
			currIndex++;
			getViewByIndex();
		}
		return 0;
	}

	@Override
	public int indexSub() {
		if (imgs != null && currIndex > 0) {
			currIndex--;
			getViewByIndex();
		}
		return 0;
	}

}
